<template>
  <div :style="{'margin-bottom': '350px', 'text-align': 'center'}">
    <el-button type="primary" size="large" @click="show">显示滑块验证码demo</el-button>
  </div>

  <div v-show="showBox" class="fth-verify-slider-mask mask">
    <div class="verifybox" :style="{ 'max-width': parseInt('310') + 48 + 'px' }">
      <div class="verifybox-top">
        <span class="title">滑块验证</span>
        <span class="verifybox-close" @click="closeBox">
          x
        </span>
      </div>
      <div class="verifybox-bottom" :style="{ padding: '15px' }">
        <!-- 验证码容器 -->
        <component
            :is="blockCaptchaComp"
            v-if="data.componentType"
            ref="instance"
            captcha-type="blockPuzzleComp"
            :vSpace="props.vSpace"
            :explain="props.explain"
            :imgSize="props.imgSize"
            :blockSize="props.blockSize"
            :barSize="props.barSize"
            @myclick="closeBox"
        />
      </div>
    </div>
  </div>

  <div>

  </div>
</template>

<script lang="ts" setup>
import blockCaptchaComp from "@/components/blockcaptcha.vue"
import {computed, ref, reactive, onMounted} from 'vue'

export interface Props {
  vSpace: number,
  explain: string,
  imgSize: Object,
  blockSize: Object,
  barSize: Object,
}

const props = withDefaults(defineProps<Props>(), {
  vSpace: 5,
  explain: "",
  imgSize: () => {
    return {
      width: '310px',
      height: '155px',
    }
  },
  blockSize: () => {
    return {
      width: '50px',
      height: '50px',
    }
  },
  barSize: () => {
    return {
      width: '310px',
      height: '34px',
    }
  },
})

const instance = ref(null)
onMounted(() => {
  console.log("main instance:", instance.value)
})

const data = reactive({
  instance: null,
  componentType: "blockPuzzleComp"
})

const clickShow = ref(false)
const showBox = computed(() => {
  return clickShow.value
})

const show = () => {
  clickShow.value = true
}

const closeBox = () => {
  clickShow.value = false
}

</script>

<style lang="scss">
.fth-verify-slider-mask {
  &.mask {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1001;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.3);
    /* display: none; */
    transition: all 0.5s;
  }

  .verifybox {
    position: relative;
    box-sizing: border-box;
    border-radius: 2px;
    border: 1px solid #e4e7eb;
    background-color: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }

  .verifybox-top {
    padding: 0 24px !important;
    height: 50px;
    line-height: 50px;
    text-align: left;
    font-size: 16px;
    color: #45494c;
    border-bottom: 1px solid #e9e9e9;
    box-sizing: border-box;

    .title {
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #222222;
    }
  }

  .ellipse:nth-of-type(1) {
    width: 28px;
    height: 28px;
    border-radius: 0 0 0 60%;
    background: rgb(141, 141, 141);
    position: absolute;
    z-index: 99;
    right: -2px;
    top: 1px;
  }

  .verifybox-bottom {
    padding: 24px 24px 28px 24px !important;
    box-sizing: border-box;
  }

  .verifybox-close {
    position: absolute;
    right: 14px;
    width: 24px;
    height: 24px;
    cursor: pointer;
  }

  .verify-tips {
    position: absolute;
    left: 0px;
    bottom: 0px;
    width: 100%;
    height: 30px;
    line-height: 30px;
    color: #fff;
  }

  .suc-bg {
    background-color: rgba(92, 184, 92, 0.5);
    filter: progid:DXImageTransform.Microsoft.gradient(startcolorstr=#7f5CB85C, endcolorstr=#7f5CB85C);
  }

  .err-bg {
    background-color: rgba(217, 83, 79, 0.5);
    filter: progid:DXImageTransform.Microsoft.gradient(startcolorstr=#7fD9534F, endcolorstr=#7fD9534F);
  }

  .tips-enter,
  .tips-leave-to {
    bottom: -30px;
  }

  .tips-enter-active,
  .tips-leave-active {
    transition: bottom 0.5s;
  }

  /* ---------------------------- */
  /*常规验证码*/
  .verify-code {
    font-size: 20px;
    text-align: center;
    cursor: pointer;
    margin-bottom: 5px;
    border: 1px solid #ddd;
  }

  .cerify-code-panel {
    height: 100%;
    overflow: hidden;
  }

  .verify-code-area {
    float: left;
  }

  .verify-input-area {
    float: left;
    width: 60%;
    padding-right: 10px;
  }

  .verify-change-area {
    line-height: 30px;
    float: left;
  }

  .varify-input-code {
    display: inline-block;
    width: 100%;
    height: 25px;
  }

  .verify-change-code {
    color: #337ab7;
    cursor: pointer;
  }

  .verify-btn {
    width: 200px;
    height: 30px;
    //   background-color: #337ab7;
    color: #ffffff;
    border: none;
    margin-top: 10px;
  }

  /*滑动验证码*/
  .verify-bar-area {
    position: relative;
    text-align: center;
    -webkit-box-sizing: content-box;
    -moz-box-sizing: content-box;
    box-sizing: content-box;
    margin-top: 14px;
    background: #f3f4f6;
  }

  .verify-bar-area .verify-move-block {
    position: absolute;
    top: -4px;
    left: 0;
    background: #fff;
    cursor: pointer;
    -webkit-box-sizing: content-box;
    -moz-box-sizing: content-box;
    box-sizing: content-box;
    box-shadow: -2px 0px 2px 0px rgba(0, 0, 0, 0.11);

    .line {
      width: 1px;
      height: 14px;
      background: #f3f4f6;
      display: inline-block;
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
    }

    .line_left {
      left: 5px;
    }

    .line_right {
      right: 5px;
    }
  }

  .verify-bar-area .verify-move-block:hover {
    color: #ffffff;
  }

  .verify-bar-area .verify-left-bar {
    position: absolute;
    //   top: -4px;
    top: 0;
    left: -1px;
    cursor: pointer;
    box-sizing: border-box;
  }

  .verify-img-panel {
    margin: 0;
    -webkit-box-sizing: content-box;
    -moz-box-sizing: content-box;
    box-sizing: content-box;
    border-top: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
    border-radius: 3px;
    position: relative;

    img {
      background: black;
    }
  }

  .verify-img-panel .verify-refresh {
    width: 25px;
    height: 25px;
    text-align: center;
    padding: 5px;
    cursor: pointer;
    position: absolute;
    top: 0;
    right: 0;
    z-index: 999;
  }

  .el-icon-refresh-right {
    color: #fff;
    font-size: 20px;
  }

  .verify-img-panel .icon-refresh {
    font-size: 20px;
    color: #fff;
  }

  .verify-img-panel .verify-gap {
    background-color: #fff;
    position: relative;
    z-index: 2;
    border: 1px solid #fff;
  }

  .verify-bar-area .verify-move-block .verify-sub-block {
    position: absolute;
    text-align: center;
    z-index: 3;
  }

  .verify-bar-area .verify-move-block .verify-icon {
    font-size: 18px;
  }

  .verify-bar-area .verify-msg {
    z-index: 3;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #222222;
  }

  .icon-check:before {
    content: ' ';
    display: block;
    width: 16px;
    height: 16px;
    position: absolute;
    margin: auto;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 9999;
    background-image: url('');
    background-size: contain;
  }

  .icon-close {
    font-size: 18px;
    position: absolute;
    margin: auto;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 9999;
    color: rgb(143, 152, 161);
  }

  .icon-right:before {
    content: ' ';
    display: block;
    width: 16px;
    height: 16px;
    position: absolute;
    margin: auto;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background-size: cover;
    z-index: 9999;
    background-image: url('');
    background-size: contain;
  }
}
</style>
